<html>
<head>
<title>Ramka.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { }
.s2 { color: rgb(128,128,128); font-style: italic; }
.s3 { color: rgb(0,0,255); }
.s4 { color: rgb(0,128,0); font-weight: bold; }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
Ramka.java</FONT>
</center></TD></TR></TABLE>
<pre>

<a name="l1"><span class="s0">import </span><span class="s1">javax.swing.*; 
<a name="l2"></span><span class="s0">import </span><span class="s1">java.awt.*; 
<a name="l3"></span><span class="s0">import </span><span class="s1">java.awt.event.ActionEvent; 
<a name="l4"></span><span class="s0">import </span><span class="s1">java.awt.event.ActionListener; 
<a name="l5"> 
<a name="l6"></span><span class="s2">/** 
<a name="l7"> * Author: Daniel Michalski 
<a name="l8"> * Date: 27.02.13 
<a name="l9"> */</span><span class="s1"> 
<a name="l10"> 
<a name="l11"></span><span class="s0">public class </span><span class="s1">Ramka </span><span class="s0">extends </span><span class="s1">JFrame { 
<a name="l12">    </span><span class="s0">private static final int </span><span class="s1">WIDTH = </span><span class="s3">400</span><span class="s1">;              </span><span class="s2">// definicja szeroskości</span><span class="s1"> 
<a name="l13">    </span><span class="s0">private static final int </span><span class="s1">HEIGHT = </span><span class="s3">100</span><span class="s1">;             </span><span class="s2">// definicja wysokości</span><span class="s1"> 
<a name="l14">     
<a name="l15">    </span><span class="s0">private </span><span class="s1">JLabel etykieta; 
<a name="l16"> 
<a name="l17">    </span><span class="s0">public </span><span class="s1">Ramka(String title) { 
<a name="l18">        </span><span class="s0">super</span><span class="s1">(title);                 </span><span class="s2">// wywoałanie kostruktowa bazowego z jednym parametrem</span><span class="s1"> 
<a name="l19">        setSize(WIDTH, HEIGHT);       </span><span class="s2">// ustaw wymiary ramki</span><span class="s1"> 
<a name="l20">        setLocationRelativeTo(</span><span class="s0">null</span><span class="s1">);  </span><span class="s2">// ustaw na środku okna</span><span class="s1"> 
<a name="l21">        initComponents();             </span><span class="s2">// zainicjalizuj etykiete oraz przycisk</span><span class="s1"> 
<a name="l22">    } 
<a name="l23"> 
<a name="l24">    </span><span class="s0">private void </span><span class="s1">initComponents() { 
<a name="l25">        JButton przyciskOk = </span><span class="s0">new </span><span class="s1">JButton(</span><span class="s4">&quot;Klinkij&quot;</span><span class="s1">);                    </span><span class="s2">// tworzy przycisk</span><span class="s1"> 
<a name="l26">        add(przyciskOk, BorderLayout.SOUTH);                            </span><span class="s2">// dodaje przycisk na dole</span><span class="s1"> 
<a name="l27"> 
<a name="l28">        etykieta = </span><span class="s0">new </span><span class="s1">JLabel(</span><span class="s4">&quot;Kliknij przycisk&quot;</span><span class="s1">);                      </span><span class="s2">// tworzy etykietę</span><span class="s1"> 
<a name="l29">        add(etykieta, BorderLayout.NORTH);                              </span><span class="s2">// dodaje etykietę na górze</span><span class="s1"> 
<a name="l30"> 
<a name="l31">        przyciskOk.addActionListener(</span><span class="s0">new </span><span class="s1">SluchaczPrzyciskuOk());        </span><span class="s2">// dodaj sluchacz do przycisku</span><span class="s1"> 
<a name="l32">    } 
<a name="l33">     
<a name="l34">    </span><span class="s0">class </span><span class="s1">SluchaczPrzyciskuOk </span><span class="s0">implements </span><span class="s1">ActionListener { 
<a name="l35">        </span><span class="s0">int </span><span class="s1">i = </span><span class="s3">1</span><span class="s1">; 
<a name="l36">        @Override 
<a name="l37">        </span><span class="s0">public void </span><span class="s1">actionPerformed(ActionEvent e) {              </span><span class="s2">// po kliknięciu w przycisk</span><span class="s1"> 
<a name="l38">            etykieta.setText(</span><span class="s4">&quot;&quot; </span><span class="s1">+ i++);                           </span><span class="s2">// zmień tekst etykiety na obecną liczbę i</span><span class="s1"> 
<a name="l39">        } 
<a name="l40">    } 
<a name="l41">} 
<a name="l42"></span></pre>
</body>
</html>